package com.lagou.consumer;

import com.lagou.pojo.Product;
import com.lagou.repository.ProductRepository;
import com.lagou.service.ProductService;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Component
public class Consumer {
    @Autowired
    private ProductService productService;

    @Autowired
    private ProductRepository productRepository;


    @KafkaListener(topics = "products")
    public void consume(ConsumerRecord record){
        Object value = record.value();
        Product product = productService.getById(Integer.parseInt(value.toString()));
        System.out.println(product);
        Product save = productRepository.save(product);
    }



}
